package com.mbmed.doctor.vcf1.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.attilax.web.reqService;
import com.mbmed.doctor.commons.utils.ModelVo;
import com.mbmed.doctor.commons.utils.StaticKeys;
import com.mbmed.doctor.vcf1.bo.Vcf1Bo;
import com.mbmed.doctor.vcf1.mapper.Vcf1;
import com.mbmed.doctor.vcf1.mapper.Vcf1Bean;

/**
 * @file  Vcf1Service.java
 * @author jiangcangpeng
 * @version 0.1
 * @todo	Vcf1服务操作接口
 * Copyright(C), 2013-2014
 *		 Shenzhen Coordinates Software Development Co., Ltd.
 * History
 *   	1. Date: 2014-10-13 09:51:21
 *      	Author: jiangcangpeng
 *      	Modification: this file was created
 *   	2. ...
 */
@Path("/vcf1")
@Component
public class Vcf1Service {
	
	private static Logger logger = Logger.getLogger(Vcf1.class);
	
	@Autowired
	private Vcf1Bo vcf1Bo;
	
	@Context
	Request request;
	
	@Context
	HttpServletRequest request1;
	
	/**http://localhost:1314/hodoctor/vcf1/getBinliFiletype?Type, VAA01, VAA07, ACF01, VAP01, AAG01, BCK01, EmpId, DeptId, DocumentId
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET   
	@Path("/getBinliFiletype")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public ModelVo getBinliFiletype(@QueryParam("VAF01") java.lang.String VAF01,@QueryParam("Debug_lBCE01") java.lang.Integer Debug_lBCE01) throws Exception{
		ModelVo modelVo = new ModelVo();
		//com.mbmed.doctor.commons.mapper.ModelVo
		 Map<String,Object> paramMap =	reqService.putMapByReqParams("Type, VAA01, VAA07, ACF01, VAP01, AAG01, BCK01, EmpId, DeptId, DocumentId",request1);
        
	//	try{
		
		 
			 
			modelVo.setResult(StaticKeys.SUCCESS);
			List<?> binliFiletype = vcf1Bo.getBinliFiletype(paramMap);
			modelVo.setList(  binliFiletype);
			 modelVo.setRows(binliFiletype);//.subList(0, 2)
		//	modelVo.setMap(map);
			modelVo.setResultMsg("ok");
//		}else{
//			modelVo.setResult(StaticKeys.ERROR);
//			modelVo.setResultMsg("没有查询到医嘱数据");
//		}
        return modelVo;
    }

	
	/**
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public List<Vcf1> getAll() throws Exception{
        List<Vcf1> list = new ArrayList<Vcf1>();
        return vcf1Bo.getAll();        
    }
	
	@SuppressWarnings("unchecked")
	@GET
	@Path("/getByVae01Vap01")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
	public ModelVo getByVae01Vap01(@QueryParam("vae01") java.lang.Integer vae01,
			@QueryParam("vap01") java.lang.Integer vap01) throws Exception{
		ModelVo mo = new ModelVo();
		List<Vcf1Bean> list = new ArrayList<Vcf1Bean>();
		Map<String,Object> paramMap = new HashMap<String, Object>(); 
		paramMap.put("vae01", vae01);
		paramMap.put("vap01", vap01);
		list = vcf1Bo.getByVae01Vap01(paramMap);
		if(list.size()>0 && list.get(0)!=null){// 
			mo.setResult(StaticKeys.SUCCESS);
			mo.setResultMsg("");
			if(list.get(0).getOutDate()==null){
				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");
				list.get(0).setOutDate(sf.format(new Date()));
			}
			mo.setRows(list);
		}else{
			mo.setResult(StaticKeys.ERROR);
			mo.setResultMsg("没有查询到数据");
		}
        return mo;
	}
	
    /**
     * 查找符合条件的所有数据库记录
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("{id}")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public Vcf1 getVcf1(@PathParam("id") String id) throws Exception{
    	Vcf1 vcf1 = null;
    	return vcf1Bo.get(id);        
    }
	
	
	/**
	 * insertVcf1
	 * @param ver1
	 * @param xml1
	 * @throws Exception
	 */
	@POST
	@Path("/insertVcf1")
	@Produces({MediaType.TEXT_HTML})
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	//这儿省略了 @Consumes 注解，JAX-RS 会自动默认为 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)，也就是 application/x-www-form-urlencoded 格式的请求。如果请求格式为 multipart/form-data，就必须显示指明：
	//@Consumes(MediaType.MULTIPART_FORM_DATA)
	public String insertVcf1(@FormParam("ver1") java.lang.String ver1,
			@FormParam("xml1") java.lang.String xml1, @Context HttpServletResponse servletResponse) throws Exception{
		String result;
		Map<String,Object> paramMap = new HashMap<String, Object>();
		paramMap.put("ver1", ver1);
		paramMap.put("xml1", xml1);
		vcf1Bo.insertVcf1ByParmMap(paramMap);
		result =  StaticKeys.SUCCESS;
		return result;
	}
	
	/**
	 * insertVcf1
	 * @param ver1
	 * @param xml1
	 * @throws Exception
	 */
	@POST
	@Path("/updateVcf1")
	@Produces({MediaType.TEXT_HTML})
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	//这儿省略了 @Consumes 注解，JAX-RS 会自动默认为 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)，也就是 application/x-www-form-urlencoded 格式的请求。如果请求格式为 multipart/form-data，就必须显示指明：
	//@Consumes(MediaType.MULTIPART_FORM_DATA)
	public String updateVcf1(
			@FormParam("CAD01") int CAD01,
			@FormParam("CBF01") int CBF01,
			@FormParam("ver1") java.lang.String ver1,
			@FormParam("xml1") java.lang.String xml1, @Context HttpServletResponse servletResponse) throws Exception{
		String result;
		Map<String,Object> paramMap = new HashMap<String, Object>();
		paramMap.put("ver1", ver1);
		paramMap.put("xml1", xml1);
		paramMap.put("CAD01", CAD01);
		paramMap.put("CBF01", CBF01);
		vcf1Bo.updateVcf1ByParmMap(paramMap);
		result =  StaticKeys.SUCCESS;
		return result;
	}
	
	
    /**
     * 向数据库中插入一条记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : 返回插入操作是否成功
     * @throws Exception
     */
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public Vcf1 saveVcf1(
			@FormParam("vcf01") java.lang.Integer vcf01,
			@FormParam("acf01") java.lang.Integer acf01,
			@FormParam("vaa01") java.lang.Integer vaa01,
			@FormParam("vaa07") java.lang.Integer vaa07,
			@FormParam("vap01") java.lang.Integer vap01,
			@FormParam("bck01") java.lang.Integer bck01,
			@FormParam("aag01") java.lang.Integer aag01,
			@FormParam("vcf08") java.lang.Byte vcf08,
			@FormParam("vcf09") java.util.Date vcf09,
			@FormParam("vcf10") java.util.Date vcf10,
			@FormParam("vcf11") java.lang.String vcf11,
			@FormParam("bce01a") java.lang.Integer bce01a,
			@FormParam("bce03a") java.lang.String bce03a,
			@FormParam("vcf14") java.lang.Byte vcf14,
			@FormParam("bce01b") java.lang.Integer bce01b,
			@FormParam("bce03b") java.lang.String bce03b,
			@FormParam("vcf17") java.util.Date vcf17,
			@FormParam("vcf18") java.lang.Byte vcf18,
			@FormParam("bce03c") java.lang.String bce03c,
			@FormParam("vcf20") java.util.Date vcf20,
			@FormParam("vcf21") java.lang.String vcf21,
			@FormParam("vcf22") java.lang.String vcf22,
			@FormParam("vcf23") java.lang.String vcf23,
			@FormParam("vcf24") java.lang.String vcf24,
			@FormParam("vcf25") java.lang.String vcf25,
			@FormParam("vcf26") java.lang.String vcf26,
			@FormParam("vcf27") java.lang.String vcf27,
			@FormParam("vcf28") java.lang.String vcf28,
			@FormParam("vcf29") java.lang.String vcf29,
			@FormParam("vcf30") java.lang.String vcf30,
			@FormParam("vcf31") java.lang.String vcf31,
			@FormParam("vcf32") java.lang.String vcf32,
			@FormParam("vcf33") java.lang.String vcf33,
			@FormParam("vcf34") java.lang.String vcf34,
			@FormParam("vcf35") java.lang.String vcf35,
			@FormParam("vcf36") java.lang.String vcf36,
			@FormParam("vcf37") java.lang.String vcf37,
			@FormParam("vcf38") java.lang.String vcf38,
			@FormParam("vcf39") java.lang.String vcf39,
			@FormParam("vcf40") java.lang.String vcf40,
			@FormParam("vcf41") java.lang.String vcf41,
			@FormParam("vcf42") java.lang.String vcf42,
			@FormParam("vcf43") java.lang.String vcf43,
			@FormParam("vcf44") java.lang.String vcf44,
			@FormParam("vcf45") java.lang.String vcf45,
			@FormParam("vcf46") java.lang.String vcf46,
			@FormParam("vcf47") java.lang.String vcf47,
			@FormParam("vcf48") java.lang.String vcf48,
			@FormParam("vcf49") java.lang.String vcf49,
			@FormParam("vcf50") java.lang.String vcf50,
			@FormParam("vcf51") java.lang.String vcf51,
			@FormParam("vcf52") java.lang.String vcf52,
			@FormParam("vcf53") java.lang.String vcf53,
			@FormParam("vcf54") java.lang.String vcf54,
			@FormParam("vcf55") java.lang.String vcf55,
			@FormParam("vcf56") java.lang.String vcf56,
			@FormParam("vcf57") java.lang.String vcf57,
			@FormParam("vcf58") java.lang.String vcf58,
			@FormParam("vcf59") java.lang.String vcf59,
			@FormParam("vcf60") java.lang.String vcf60,
			@FormParam("vcf61") java.lang.String vcf61,
			@FormParam("vcf62") java.lang.String vcf62,
			@FormParam("vcf63") java.lang.String vcf63,
			@FormParam("vcf64") java.lang.String vcf64,
			@FormParam("vcf65") java.lang.String vcf65,
			@FormParam("vcf66") java.lang.String vcf66,
			@FormParam("vcf67") java.lang.String vcf67,
			@FormParam("vcf68") java.lang.String vcf68,
			@FormParam("vcf69") java.lang.String vcf69,
			@FormParam("vcf70") java.lang.String vcf70,
			@FormParam("vcf71") java.lang.String vcf71,
			@FormParam("vcf72") java.lang.String vcf72,
			@FormParam("vcf73") java.lang.String vcf73,
			@FormParam("vcf74") java.lang.String vcf74,
			@FormParam("vcf75") java.lang.String vcf75,
			@FormParam("vcf76") java.lang.String vcf76,
			@FormParam("vcf77") java.lang.String vcf77,
			@FormParam("vcf78") java.lang.String vcf78,
			@FormParam("vcf79") java.lang.String vcf79,
			@FormParam("vcf80") java.lang.String vcf80,
			@FormParam("vcf81") java.lang.String vcf81,
			@FormParam("vcf82") java.lang.String vcf82,
			@FormParam("vcf83") java.lang.String vcf83,
			@FormParam("vcf84") java.lang.String vcf84,
			@FormParam("vaq01") java.lang.Integer vaq01,
			@FormParam("vcf86") java.lang.Byte vcf86,
			@Context HttpServletResponse servletResponse
	) throws Exception {
		Vcf1 vcf1 = new Vcf1();
		vcf1.setVcf01(vcf01);
		vcf1.setAcf01(acf01);
		vcf1.setVaa01(vaa01);
		vcf1.setVaa07(vaa07);
		vcf1.setVap01(vap01);
		vcf1.setBck01(bck01);
		vcf1.setAag01(aag01);
		vcf1.setVcf08(vcf08);
		vcf1.setVcf09(vcf09);
		vcf1.setVcf10(vcf10);
		vcf1.setVcf11(vcf11);
		vcf1.setBce01a(bce01a);
		vcf1.setBce03a(bce03a);
		vcf1.setVcf14(vcf14);
		vcf1.setBce01b(bce01b);
		vcf1.setBce03b(bce03b);
		vcf1.setVcf17(vcf17);
		vcf1.setVcf18(vcf18);
		vcf1.setBce03c(bce03c);
		vcf1.setVcf20(vcf20);
		vcf1.setVcf21(vcf21);
		vcf1.setVcf22(vcf22);
		vcf1.setVcf23(vcf23);
		vcf1.setVcf24(vcf24);
		vcf1.setVcf25(vcf25);
		vcf1.setVcf26(vcf26);
		vcf1.setVcf27(vcf27);
		vcf1.setVcf28(vcf28);
		vcf1.setVcf29(vcf29);
		vcf1.setVcf30(vcf30);
		vcf1.setVcf31(vcf31);
		vcf1.setVcf32(vcf32);
		vcf1.setVcf33(vcf33);
		vcf1.setVcf34(vcf34);
		vcf1.setVcf35(vcf35);
		vcf1.setVcf36(vcf36);
		vcf1.setVcf37(vcf37);
		vcf1.setVcf38(vcf38);
		vcf1.setVcf39(vcf39);
		vcf1.setVcf40(vcf40);
		vcf1.setVcf41(vcf41);
		vcf1.setVcf42(vcf42);
		vcf1.setVcf43(vcf43);
		vcf1.setVcf44(vcf44);
		vcf1.setVcf45(vcf45);
		vcf1.setVcf46(vcf46);
		vcf1.setVcf47(vcf47);
		vcf1.setVcf48(vcf48);
		vcf1.setVcf49(vcf49);
		vcf1.setVcf50(vcf50);
		vcf1.setVcf51(vcf51);
		vcf1.setVcf52(vcf52);
		vcf1.setVcf53(vcf53);
		vcf1.setVcf54(vcf54);
		vcf1.setVcf55(vcf55);
		vcf1.setVcf56(vcf56);
		vcf1.setVcf57(vcf57);
		vcf1.setVcf58(vcf58);
		vcf1.setVcf59(vcf59);
		vcf1.setVcf60(vcf60);
		vcf1.setVcf61(vcf61);
		vcf1.setVcf62(vcf62);
		vcf1.setVcf63(vcf63);
		vcf1.setVcf64(vcf64);
		vcf1.setVcf65(vcf65);
		vcf1.setVcf66(vcf66);
		vcf1.setVcf67(vcf67);
		vcf1.setVcf68(vcf68);
		vcf1.setVcf69(vcf69);
		vcf1.setVcf70(vcf70);
		vcf1.setVcf71(vcf71);
		vcf1.setVcf72(vcf72);
		vcf1.setVcf73(vcf73);
		vcf1.setVcf74(vcf74);
		vcf1.setVcf75(vcf75);
		vcf1.setVcf76(vcf76);
		vcf1.setVcf77(vcf77);
		vcf1.setVcf78(vcf78);
		vcf1.setVcf79(vcf79);
		vcf1.setVcf80(vcf80);
		vcf1.setVcf81(vcf81);
		vcf1.setVcf82(vcf82);
		vcf1.setVcf83(vcf83);
		vcf1.setVcf84(vcf84);
		vcf1.setVaq01(vaq01);
		vcf1.setVcf86(vcf86);

		return vcf1 = vcf1Bo.save(vcf1);

	}
	/**
     * 删除数据库中与传入的值对象对应的记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : boolean 返回删除操作是否成功
     * @throws Exception
     */
	@DELETE
	@Path("{id}")
	public boolean removeVcf1(@PathParam("id") String id) throws Exception{
		if(id == null) return false;
    	return vcf1Bo.remove(id);
	}
	
}
